package ExpressOne;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ControlDisplay extends JFrame implements ActionListener {
    JTextField tf_controlBar;
    JButton btn_touch;
    JTextArea ta_display;
    MemoryShow show;
    ControlDisplay() {
        //进行初始化工作
        super("操作");
        tf_controlBar = new JTextField();//上面的命令输入条
        tf_controlBar.setFont(new Font("宋体", Font.BOLD, 18));

        btn_touch = new JButton("进行操作");//操作按钮
        ta_display = new JTextArea();//显示框框

        show=new MemoryShow();

        //panel=new JPanel(new GridLayout(2,4));
        //容器
        JPanel panel = new JPanel();
        tf_controlBar.setColumns(15);
        panel.add(tf_controlBar, BorderLayout.NORTH);
        panel.add(btn_touch, BorderLayout.CENTER);


        //父层容器添加
        //setLayout(new GridLayout(2,4));//父层容器设置两行四列
        add(panel, BorderLayout.NORTH);

        ta_display.setFont(new Font("宋体", Font.BOLD, 18));
        ta_display.setText("内存查看情况");
        ta_display.setEnabled(false);
        ta_display.setDisabledTextColor(Color.GREEN);
        add(new JScrollPane(ta_display), BorderLayout.CENTER);

        //设置菜单
        JMenuItem item1 = new JMenuItem("帮助");
        JMenuItem item2 = new JMenuItem("退出");

        JMenu menu = new JMenu("文件");
        JMenuBar menuBar = new JMenuBar();

        menu.add(item1);
        menu.add(item2);
        menuBar.add(menu);
        setJMenuBar(menuBar);

        //添加事件监听器
        item1.addActionListener(this);
        item2.addActionListener(this);
        btn_touch.addActionListener(this);

        //设置容器默认情况
        setResizable(false);
        setBounds(600, 200, 300, 300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        switch (e.getActionCommand()) {
            case "帮助":
                JOptionPane.showMessageDialog(null,
                        "格式：C+PID+MemorySize\n", "帮助", JOptionPane.INFORMATION_MESSAGE);
                break;
            case "退出":
                System.exit(0);
            case "进行操作":
                String[] str = tf_controlBar.getText().split(" ");
                switch (str[0]) {
                    //创建线程
                    case "c":
                    case "C":

                        if(str.length>3)
                            break;
                        int start,size;
                        try {
                            start=Integer.parseInt(str[1]);
                            size=Integer.parseInt(str[2]);
                        }catch (Exception ex){
                            JOptionPane.showMessageDialog(null,"输入格式错误");
                        }
                        //show.addToReady();
                        break;
                    //就绪态到执行态
                    case "p":
                    case "P":
                        break;
                    //执行态回到就绪态
                    case "t":
                    case "T":
                        break;
                    //执行态到阻塞态
                    case "b":
                    case "B":
                        break;
                    //阻塞态到就绪态
                    case "w":
                    case "W":
                        break;
                    //执行态结束
                    case "e":
                    case "E":
                        break;
                    //帮助
                    case "H":
                    case "h":
                        break;
                    //进程状态
                    case "s":
                    case "S":
                        break;
                    //内存中的空区
                    case "M":
                    case "m":
                        break;
                    default:
                        JOptionPane.showMessageDialog(null, "错误输入");
                        break;
                }
                break;
        }

    }

    public static void main(String[] args) {
        new ControlDisplay();
    }
}
